﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;


namespace Liang.UI
{
   public  class DataGridViewLinkColumnEx : DataGridViewLinkColumn
    {

        static Size DefaultLinkSize = new Size(80, 24);

        private Size m_LinkSize = DefaultLinkSize;
        [Category("Jonson Design"), Browsable(true), Localizable(true), Description("链接列大小模板")]
        public Size LinkSize
        {
            get { return m_LinkSize; }
            set { m_LinkSize = value; }
        }

        private String m_LinkText = @"操作"; //String.Empty;
        [Category("Jonson Design"), Browsable(true), Localizable(true), Description("链接列默认文本")]
        public String LinkText
        {
            get { return m_LinkText; }
            set { m_LinkText = value; }
        }

        public override object Clone()
        {
            DataGridViewLinkColumnEx column = (DataGridViewLinkColumnEx)base.Clone();
            column.LinkText = m_LinkText;
            return column;
        }

        public DataGridViewLinkColumnEx()
            : base()
        {
            this.CellTemplate = new DataGridViewLinkCellEx();
        }

    }

   public class DataGridViewLinkCellEx : DataGridViewLinkCell
   {
       #region "type:designer properties"

       private bool m_enabled = true;
       [Category("Jonson Design"), Browsable(true), Localizable(true), Description("是否可用")]
       public bool Enabled
       {
           get { return m_enabled; }
           set { m_enabled = value; }
       }

       /// <summary>
       /// 这里链接的可见进行重写，原有的是从column中统一设置，
       /// 通过此属性可以单独设置是否可见
       /// </summary>
       private bool m_visible = true;
       [Category("Jonson Design"), Browsable(true), Localizable(true), Description("是否可见")]
       public new bool Visible
       {
           get { return m_visible; }
           set { m_visible = value; }
       }

       /// <summary>
       /// 如果链接文本没有单独设置的话，将使用column中设置的文本
       /// </summary>
       private string m_text = string.Empty;
       [Category("Jonson Design"), Browsable(true), Localizable(true), Description("链接文本")]
       public string Text
       {
           get
           {
               if (string.IsNullOrEmpty(m_text))
                   m_text = this.OwningColumnEx.LinkText;
               return m_text;
           }
           set
           {
               m_text = value;
           }
       }

       /// <summary>
       /// 如果链接大小没有单独设置的话，将使用column中设置的大小
       /// </summary>
       private Size m_size = Size.Empty;

       [Category("Jonson Design"), Browsable(true), Localizable(true), Description("链接文本")]
       public new Size Size
       {
           get
           {
               if (m_size.IsEmpty)
                   m_size = this.OwningColumnEx.LinkSize;
               return m_size;
           }
           set
           {
               m_size = value;
           }
       }

       [Category("Jonson Design"), Browsable(true), Localizable(true), Description("所属列")]
       public DataGridViewLinkColumnEx OwningColumnEx
       {
           get { return this.OwningColumn as DataGridViewLinkColumnEx; }
       }

       [Category("Jonson Design"), Browsable(true), Localizable(true), Description("所属表格")]
       public DataGridViewEx DataGridViewEx
       {
           get { return this.DataGridView as DataGridViewEx; }
       }
       #endregion

      

   }
}
